<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>九宫格布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        #warp {
            overflow: hidden;
           
        }
        #warp.item {
            width: 248px;
            height: 360px;
            font-size: 13px;
            
        }
        .title {
            width: 248px;
            height: 30px;
            line-height: 30px;
            overflow: hidden;
            margin-bottom: 10px;
        }
        .imgContainer {
            width: 248px;
            display: table-cell;
            text-align: center;
        }
        img {
            width: 100%;
        }
        .price {
            color: #ff6700;
            font-size: 18px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="cols">
        <button>三列</button>
        <button>四列</button>
        <button>五列</button>
        <button>适应屏幕</button>
    </div>
    <div id="warp">
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
            <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
            <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
        <div class="item">
            <div class="imgContainer">
                <img src="images/1.png" alt="">
            </div>
                <p class="title">纯色短袖女春秋季T恤韩版国际新款服装2019潮</p>
                <p class="price">￥69</p>
        </div>
    </div>
    <script>
        var btns=document.getElementsByTagName('button');
        var items=document.getElementsByClassName('item');
        btns[0].onclick=function(){
            for (var i=0;i<items.length;i++){
                items[i].style.float='left';
                items[i].parentNode.style.width=(1+3*items[i].offsetWidth)+'px';
            }
        }
        btns[1].onclick=function(){
            for (var i=0;i<items.length;i++){
                items[i].style.float='left';
                items[i].parentNode.style.width=(1+4*items[i].offsetWidth)+'px';
            }
        }
        btns[2].onclick=function(){
            for (var i=0;i<items.length;i++){
                items[i].style.float='left';
                items[i].parentNode.style.width=(1+5*items[i].offsetWidth)+'px';
            }
        }
        btns[3].onclick=function(){
            for (var i=0;i<items.length;i++){
                items[i].style.float='left';
            }
        }
    </script>
</body>
</html>